package com.hmall.search.mq;

import com.hmall.search.constants.MqConstants;
import com.hmall.search.service.SearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {
    @Autowired
    private SearchService searchService;

    /**
     * 监听商品新增或修改的业务
     * @param id item的id
     */
    @RabbitListener(queues = MqConstants.ITEM_INSERT_UPDATE_QUEUE)
    public void listenItemlInsertOrUpdate(Long id){
        searchService.insertById(id);
    }

    /**
     * 监听商品删除的业务
     */
    @RabbitListener(queues = MqConstants.ITEM_DELETE_QUEUE)
    public void listenItemDelete(Long id){
        searchService.deleteById(id);
    }

}
